package com.IClass;

import java.util.List;
import java.util.Map;

import com.IClass.App.R;
import com.IClass.image.AsynImageLoader;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class iAskListAdapter extends BaseAdapter {
	public static String TAG = "iAskListAdapter";
	private AsynImageLoader mImageAsynLoader;
	private Context context;                        //运行上下文   
	private List<Map<String, Object>> listItems;    //商品信息集合   
	private LayoutInflater listContainer;           //视图容器   
	
	 public final class ListItemView{                //自定义控件集合     
         public ImageView userimage;     
         public TextView userfeed;     
         public TextView username;   
      
  }   
	 
	public iAskListAdapter(Context context, List<Map<String, Object>> listItems) 
	{   
	        this.context = context;            
	        listContainer = LayoutInflater.from(context);   //创建视图容器并设置上下文   
	        this.listItems = listItems;   
	        mImageAsynLoader = new AsynImageLoader();
	} 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		Map<String, String> map = (Map<String, String>)this.getItem(position);//存放图片所对应的url
		
		ListItemView  listItemView = null;
		if (convertView == null) {   
            listItemView = new ListItemView();    
            //获取list_item布局文件的视图   
            convertView = listContainer.inflate(R.layout.appshowviewitem, null);   
            //获取控件对象   

            
            listItemView.userimage = (ImageView)convertView.findViewById(R.id.userimage);
            listItemView.userfeed = (TextView)convertView.findViewById(R.id.userfeed);
            listItemView.username = (TextView)convertView.findViewById(R.id.username);
            
            convertView.setTag(listItemView);
            
            listItemView.userimage.setTag(map.get("userimage"));
            
		}
		else
		{
			listItemView = (ListItemView)convertView.getTag();   
		}	
		listItemView.userfeed.setText(map.get("userfeed"));
		listItemView.username.setText(map.get("username"));
			
		
		
		mImageAsynLoader.loadBitmap(listItemView.userimage,ImageUtil.getBitmapById(convertView.getContext(), R.drawable.icon_3_n));
		
		
		
		
		return convertView;
	}



	@Override
	public int getCount() {
		return this.listItems.size();
	}

	@Override
	public Object getItem(int position) {
		return this.listItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}


}